package com.linhngua.code.gwt.client.data;

import java.util.HashSet;
import java.util.LinkedList;
import java.util.Queue;

public class LimitedSizeSet<E> extends HashSet<E> {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	private int limitedSize;

	private Queue<E> queue;

	public LimitedSizeSet(){
		
	}
	public LimitedSizeSet(int limit) {
		queue = new LinkedList<E>();
		limitedSize = limit;
	}

	public boolean add(E e) {
		queue.add(e);

		super.add(e);
		if (size() > limitedSize) {
			super.remove(queue.poll());
		}

		return true;
	};

}
